package iagovsothello.logger;

import iagovsothello.ai.Agent;
import iagovsothello.ai.Greedy;
import iagovsothello.ai.Minimax;
import iagovsothello.ai.Randomizer;

import java.util.*;


public class ExperimentQueue extends Experiment {

	private static final long serialVersionUID = 8866633710347225518L;
	private LinkedList<Experiment> queue;
	
	public ExperimentQueue(String name) 
	{
		super(name, 0);
		this.queue = new LinkedList<Experiment>();
	}

	public ExperimentQueue(String name, List<Experiment> list) 
	{
		super(name, 0);
		this.queue = new LinkedList<Experiment>(list);
	}
	
//	public static void main(String[] args) 
//	{
//		LinkedList<Agent> opponents = new LinkedList<Agent>();
//		opponents.add(new Randomizer());
//		opponents.add(new Greedy());
//		opponents.add(new Minimax());
//		
//		ExperimentQueue queue = new ExperimentQueue("TEST");
//		ClashExperiment ex1 = new ClashExperiment("TEST-MINIMAX",4,100,new Minimax(),opponents,false);
//		queue.add(ex1);
//		ClashExperiment ex2 = new ClashExperiment("TEST-GREEDY",4,100,new Greedy(),opponents,false);
//		queue.add(ex2);
//		
//		queue.start();
//	}
	
	public void add(Experiment e)
	{
		if (!queue.isEmpty())
		{
			Experiment last = queue.getLast();
			last.setNext(e);
		}
		queue.add(e);
	}

	@Override
	protected void execute() 
	{
		if (!queue.isEmpty())
		{
			queue.getFirst().start();
		}
	}

	@Override
	protected void end() 
	{
		//niente
	}

	@Override
	protected void print()
	{
		//niente
	}
	
	public void addObserverRecursive(Observer o)
	{
		for (Experiment exp : queue)
		{
			exp.addObserverRecursive(o);
		}
	}
	
	public void printRecursive()
	{
		for (Experiment exp : queue)
		{
			exp.printRecursive();
		}
	}
	
	@Override
	public int size() 
	{
		return queue.size();
	}
	
	@Override
	public int totalSize() 
	{
		int size = 0;
		for (Experiment exp : queue)
		{
			size += exp.totalSize();
		}
		return size;
	}
}
